'use strict';
/**
 * @name: node封装淘宝的top接口
 * @description: 针对于框架进行了封装
 * @version: 0.0.1
 * @author: xiech
 * @Date: 2020-12-10 13:53:30
 * @LastEditors: xiech
 * @LastEditTime: 2020-12-10 13:53:30
 */

module.exports = async (ctx) => {
  const mftop = {};
  const topApi = ctx.cloud.topApi;
  const session = ctx.topSession;
  /**
   * @description: top接口
   * @param {string} api 集合
   * @param {object} data 数据
   * @return {object} top接口数据
   */
  mftop.topApi = async (api, data) => {
    // 给数据增加 session
    data = Object.assign({ session }, data);
    return new Promise((resolve,reject) => {
      topApi.execute(api, data, (error, response) => {
        if (!error) {
          resolve(response);
        } else {
          reject(error);
        }
      });
    });
  };


  return mftop;
}